<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="resources/css/bootstrap.min.css" />
  <link rel="stylesheet" href="resources/css/bootstrap-responsive.min.css" />
  <link rel="stylesheet" href="resources/css/matrix-login.css" />
  <link href="resources/font-awesome/css/font-awesome.css" rel="stylesheet" />
  <link rel="stylesheet" href="resources/css/jquery.gritter.css" />
  <link rel="icon" href="resources/img/icon.png" sizes="512x512">
</head>
<body>
<h3>用户登录注册</h3><br>
<button id="registe">用户注册</button>
<button id="loginoj">OJ登录</button>
<button id="logout">退出</button>
<h3>角色管理</h3>
<button id="addrole">新增角色</button>
<button id="updaterole">更新角色</button>

<h3>权限管理</h3>
<button id="addpermission">新增权限</button>
<button id="updatepermission">更新权限</button>
<button id="deletepermission">删除权限</button>
<h3>角色赋予权限</h3>
<button id="addpermissionforrole">角色赋予权限</button>
<br>
<h3><a href="./user">用户管理</a></h3>
</body>
<script src="resources/js/jquery.min.js"></script>
<script src="resources/js/matrix.login.js"></script>
<script src="resources/js/jquery.gritter.min.js"></script>
<script src="resources/js/vue.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	$("#registe").click(registe);
	$("#logout").click(logout);
	
	$("#addrole").click(addrole);
	$("#updaterole").click(updaterole);
	
	$("#addpermission").click(addpermission);
	$("#updatepermission").click(updatepermission);
	$("#deletepermission").click(deletepermission);
	
	$("#addpermissionforrole").click(addpermissionforrole);
	
	
	$("#loginoj").click(loginoj);
});

function registe(){
	$.ajax("./common/login/registe", 
			{
			dataType : "json", 
   			type : "post", 
		   contentType:"application/json", 
		   data:JSON.stringify({"username":"anson","password":"123","userType":"admin"}),
		   success :function(data){
			   console.log(data);
		   },
		   error:function(){
			   alert("数据发送失败");
		   }
	});
}


function logout(){
	$.ajax("./common/login/sign/out", 
			{
			dataType : "json", 
   			type : "get", 
		   contentType:"application/json", 
		   data:{},
		   success :function(data){
			   console.log(data);
		   },
		   error:function(){
			   alert("数据发送失败");
		   }
	});
}

/**
 * {"roleName":"角色根节点","roleType":"group","roleLevel":0}
 * {"roleParentId":"","roleName":"角色根节点","roleIndex":"","roleType":"group","roleLevel":0}
 */
function addrole(){
	$.ajax("./manage/role/save", 
			{
			dataType : "json", 
   			type : "post", 
		   contentType:"application/json", 
		   data:JSON.stringify({"roleParentId":"2B5C787600C041419583A1DF533C8F80","roleName":"测试账户","roleIndex":3,"roleType":"role","roleLevel":2}),
		   success :function(data){
			   console.log(data);
		   },
		   error:function(){
			   alert("数据发送失败");
		   }
	});
}

 
 function updaterole(){
		$.ajax("./manage/role/update", 
				{
				dataType : "json", 
	   			type : "post", 
			   contentType:"application/json", 
			   data:JSON.stringify({"roleId":"D895D0759CA542FCBDDE858A6C2DE901","roleName":"admin"}),
			   success :function(data){
				   console.log(data);
			   },
			   error:function(){
				   alert("数据发送失败");
			   }
		});
 }
 
 
 /**
 {"permissionName":"权限根节点","permissionType":"group","permissionLevel":0}
 {"permissionParentId":"","permissionName":"","permissionIndex":"","permissionType":"","permissionLevel":""}
 */
 function addpermission(){
		$.ajax("./manage/permission/save", 
				{
				dataType : "json", 
	   			type : "post", 
			   contentType:"application/json", 
			   data:JSON.stringify( {"permissionParentId":"D4EE79B2A6D6494CB03F5145E2E2D940","permissionName":"download","permissionIndex":5,"permissionType":"permission","permissionLevel":2}),
			   success :function(data){
				   console.log(data);
			   },
			   error:function(){
				   alert("数据发送失败");
			   }
		});
	}
 
 
 function updatepermission(){
		$.ajax("./manage/permission/update", 
				{
				dataType : "json", 
	   			type : "post", 
			   contentType:"application/json", 
			   data:JSON.stringify({"userId":"CE70FDA484E0449D8676FD85660F51B7","roleId":"D895D0759CA542FCBDDE858A6C2DE901"}),
			   success :function(data){
				   console.log(data);
			   },
			   error:function(){
				   alert("数据发送失败");
			   }
		});
	}
 
 function deletepermission(){
		$.ajax("./manage/permission/delete", 
				{
				dataType : "json", 
	   			type : "post", 
			   contentType:"application/json", 
			   data:JSON.stringify({"permissionId":"0BA4C7BE9DA949E4BB8E02F545A12F5D"}),
			   success :function(data){
				   console.log(data);
			   },
			   error:function(){
				   alert("数据发送失败");
			   }
		});
	}
 
 
 function addpermissionforrole(){
		$.ajax("./manage/permission/role/save", 
				{
				dataType : "json", 
	   			type : "post", 
			   contentType:"application/json", 
			   data:JSON.stringify({"roleId":"D895D0759CA542FCBDDE858A6C2DE901","permissionId":"0BA4C7BE9DA949E4BB8E02F545A12F5D"}),
			   success :function(data){
				   console.log(data);
			   },
			   error:function(){
				   alert("数据发送失败");
			   }
		});
	}
 
 
 function loginoj(){
		$.ajax("./common/login/sign/check/in", 
				{
				dataType : "json", 
	   			type : "post", 
			   contentType:"application/json", 
			   data:{},
			   success :function(data){
				   console.log(data);
			   },
			   error:function(){
				   alert("数据发送失败");
			   }
		});
	}
</script>
</html>